package com.example.gw_back_end.controller;

import com.example.gw_back_end.domain.Result;
import com.example.gw_back_end.domain.entities.Friendship;
import com.example.gw_back_end.service.FriendshipService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("friend")
public class FriendshipController {
    private final FriendshipService friendshipService;
    public FriendshipController(FriendshipService friendshipService) {
        this.friendshipService = friendshipService;
    }

    @GetMapping("get_friendship_list")
    public Result getFriendList() {
        return Result.success(friendshipService.getFriendshipList());
    }

    @PostMapping("add_friendship")
    public Result addFriendship(@RequestBody Integer friendUserId) {
        if (friendshipService.addFriendship(friendUserId)) {
            return Result.success();
        } else {
            return Result.error();
        }
    }

    @PutMapping("update_friendship")
    public Result updateFriendship(@RequestBody Friendship friendship) {
        if (friendshipService.updateFriendship(friendship)) {
            return Result.success();
        } else {
            return Result.error();
        }
    }
}
